#ifndef HINIC3_CSR_ADDR_COMMON_H
#define HINIC3_CSR_ADDR_COMMON_H


#include "infra_pub.h"
#include "node_id.h"

#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif /* __cplusplus */

#define CSR_PHY_ADDR_GEN_CPB(addr) CSR_PHY_ADDR_GEN(NODE_ID_CPB, addr)
#define CSR_PHY_ADDR_GEN_QUL(addr) CSR_PHY_ADDR_GEN(NODE_ID_QUL, addr)
#define CSR_PHY_ADDR_GEN_QUF(addr) CSR_PHY_ADDR_GEN(NODE_ID_QUF, addr)
#define CSR_PHY_ADDR_GEN_ISCH(addr) CSR_PHY_ADDR_GEN(NODE_ID_QUL, addr) /* iSCH use QU's Node id */
#define CSR_PHY_ADDR_GEN_ESCH(addr) CSR_PHY_ADDR_GEN(NODE_ID_QUL, addr)
#define CSR_PHY_ADDR_GEN_MQM(addr) CSR_PHY_ADDR_GEN(NODE_ID_MQM, addr)
#define CSR_PHY_ADDR_GEN_LCAM(addr) CSR_PHY_ADDR_GEN(NODE_ID_LCAM, addr)

#define CSR_PHY_ADDR_GEN_TILE_L0(addr) CSR_PHY_ADDR_GEN(NODE_ID_TILE_L0, addr)
#define CSR_PHY_ADDR_GEN_TILE_L1(addr) CSR_PHY_ADDR_GEN(NODE_ID_TILE_L1, addr)
#define CSR_PHY_ADDR_GEN_TILE_L2(addr) CSR_PHY_ADDR_GEN(NODE_ID_TILE_L2, addr)
#define CSR_PHY_ADDR_GEN_TILE_L3(addr) CSR_PHY_ADDR_GEN(NODE_ID_TILE_L3, addr)

#define CSR_PHY_ADDR_GEN_TILE_F0(addr) CSR_PHY_ADDR_GEN(NODE_ID_TILE_F0, addr)
#define CSR_PHY_ADDR_GEN_TILE_F1(addr) CSR_PHY_ADDR_GEN(NODE_ID_TILE_F1, addr)
#define CSR_PHY_ADDR_GEN_TILE_F2(addr) CSR_PHY_ADDR_GEN(NODE_ID_TILE_F2, addr)
#define CSR_PHY_ADDR_GEN_TILE_F3(addr) CSR_PHY_ADDR_GEN(NODE_ID_TILE_F3, addr)

#define CSR_PHY_ADDR_GEN_PETX(addr) CSR_PHY_ADDR_GEN(NODE_ID_DP_NETWORK, addr)
#define CSR_PHY_ADDR_GEN_PERX(addr) CSR_PHY_ADDR_GEN(NODE_ID_DP_HOST, addr)

#define CSR_PHY_ADDR_GEN_IPSUTX(addr) CSR_PHY_ADDR_GEN(NODE_ID_DP_HOST, addr)
#define CSR_PHY_ADDR_GEN_IPSURX(addr) CSR_PHY_ADDR_GEN(NODE_ID_DP_NETWORK, addr)

#define CSR_PHY_ADDR_GEN_SML0(addr) CSR_PHY_ADDR_GEN(NODE_ID_SML0, addr)
#define CSR_PHY_ADDR_GEN_SML1(addr) CSR_PHY_ADDR_GEN(NODE_ID_SML1, addr)
#define CSR_PHY_ADDR_GEN_SML2(addr) CSR_PHY_ADDR_GEN(NODE_ID_SML2, addr)
#define CSR_PHY_ADDR_GEN_SML3(addr) CSR_PHY_ADDR_GEN(NODE_ID_SML3, addr)

#define CSR_PHY_ADDR_GEN_SMF0(addr) CSR_PHY_ADDR_GEN(NODE_ID_SMF0, addr)
#define CSR_PHY_ADDR_GEN_SMF1(addr) CSR_PHY_ADDR_GEN(NODE_ID_SMF1, addr)
#define CSR_PHY_ADDR_GEN_SMF2(addr) CSR_PHY_ADDR_GEN(NODE_ID_SMF2, addr)
#define CSR_PHY_ADDR_GEN_SMF3(addr) CSR_PHY_ADDR_GEN(NODE_ID_SMF3, addr)

#define CSR_PHY_ADDR_GEN_CRYPT(addr) CSR_PHY_ADDR_GEN(NODE_ID_CRYPTO, addr)

#define CSR_PHY_ADDR_GEN_ROB(addr) CSR_PHY_ADDR_GEN(NODE_ID_TS, addr)
#define CSR_PHY_ADDR_GEN_ISC(addr) CSR_PHY_ADDR_GEN(NODE_ID_TS, addr)
#define CSR_PHY_ADDR_GEN_ESC(addr) CSR_PHY_ADDR_GEN(NODE_ID_TS, addr)
#define CSR_PHY_ADDR_GEN_TS_TOP(addr) CSR_PHY_ADDR_GEN(NODE_ID_TS, addr)

#define CSR_PHY_ADDR_GEN_SM(sm_id, addr) CSR_PHY_ADDR_GEN(tool_sm_get_nodeid(sm_id), (addr))

/* STLIQ */
#define IND_STLIQ_MEM_PREALLOC (6)
#define IND_STLIQ_MEM_OQID (7)
#define IND_STLIQ_MEM_PRO_TYPE (9)
#define IND_STLIQ_MEM_ICHANNEL (10)
#define IND_STLIQ_MEM_PCPTR (11)
#define IND_STLIQ_MEM_STL_EVT_ICHNL (14)
#define IND_STLIQ_MEM_STF_EVT_ICHNL (15)

/* STFIQ */
#define IND_STFIQ_MEM_MSG_SRV (1)
#define IND_STFIQ_MEM_ICHANNEL (3)
#define IND_STFIQ_MEM_PREALLOC (15)
#define IND_STFIQ_MEM_PCPTR (16)
#define IND_STFIQ_MEM_PCOFFSET (17)

/* PRMTX & PRMRX */
#define IND_PRM_G_COS_TH (0)
#define IND_PRM_G_P_TH (1)
#define IND_PRM_G_SRV_TH (2)
#define IND_PRM_Y_STF_P_TH (3)
#define IND_PRM_Y_STF_SRV_TH (4)
#define IND_PRM_R_STF_P_TH (5)
#define IND_PRM_R_STF_SRV_TH (6)
#define IND_PRM_Y_STL_P_TH (7)
#define IND_PRM_Y_STL_SRV_TH (8)
#define IND_PRM_R_STL_P_TH (9)
#define IND_PRM_R_STL_SRV_TH (10)

/*
(Configurations)
0x0: port group threshold configure table.
0x1:red zone port configure threshold table.
0x2:yellow zone port configure threshold table.
0x3:network side port configure threshold table.
0x4:network side cos configure threshold table.
0x5 : host side EP group configure threshold table.
0x6 : host side srv group (per service) configure threshold table.
0x7 : host side port group(per host per service) configure threshold table.
0x8 : host side pri group (per cos per host per service) configure threshold table.
0x9 : host side queue group (per cos per ep for normal queues) configure threshold table.
*/
#define IND_MEM_QU_PDM_PORT_GRP_THD_CFG_TBL (0x0)
#define IND_MEM_QU_PDM_RED_ZONE_PORT_CFG_THD_TBL (0x1)
#define IND_MEM_QU_PDM_YELLOW_ZONE_PORT_CFG_THD_TBL (0x2)
#define IND_MEM_QU_PDM_NETWORK_SIDE_PORT_CFG_THD_TBL (0x3)
#define IND_MEM_QU_PDM_NETWORK_SIDE_COS_CFG_THD_TBL (0x4)
#define IND_MEM_QU_PDM_HOST_SIDE_EP_GRP_CFG_THD_TBL (0x5)
#define IND_MEM_QU_PDM_HOST_SIDE_SRV_GRP_CFG_THD_TBL (0x6)
#define IND_MEM_QU_PDM_HOST_SIDE_PORT_GRP_CFG_THD_TBL (0x7)
#define IND_MEM_QU_PDM_HOST_SIDE_PRI_GRP_CFG_THD_TBL (0x8)
#define IND_MEM_QU_PDM_HOST_SIDE_QUE_GRP_CFG_THD_TBL (0x9)

typedef union {
    struct {
        unsigned long long pg_fc_th_dif2 : 8; // [71:64]
        unsigned long long pg_rsvd_th : 16;   // [87:72]
        unsigned long long pg_drp_th_on : 16; // [103:88]
        unsigned long long pg_drp_th_dif : 8; // [111:104]
        unsigned long long pg_max_sh_th : 15; // [126:112]
        unsigned long long pg_sh_fc_dyn : 1;  // [127]

        unsigned long long pg_fc_th_on0 : 16; // [15:0]
        unsigned long long pg_fc_th_on1 : 16; // [31:16]
        unsigned long long pg_fc_th_on2 : 16; // [47:32]
        unsigned long long pg_fc_th_dif0 : 8; // [55:48]
        unsigned long long pg_fc_th_dif1 : 8; // [63:56]
    } bs;

    unsigned long long val64[2];
} u_qu_pdm_port_grp_thd_cfg;

/*
Red cell occupied threshold table
Yellow cell occupied threshold table
*/
typedef union {
    struct {
        unsigned long long port_rsvd_th : 16;  // [15:0]
        unsigned long long port_bp_th_dif : 8; // [23:16]
        unsigned long long port_bp_th : 16;    // [39:24]
        unsigned long long resv0 : 24;         // [63:40]
    } bs;
    unsigned long long val64;
} u_qu_pdm_color_zone_cfg;

/*
    Network Port cell occupied threshold table Fields Definition
    This table was indexed with :
"	TP/Mac :  {1'b0,port [3:0]}.
"	Mc : 16.

*/
typedef union {
    struct {
        unsigned long long port_fc_th_dif2 : 8; // [71:64]
        unsigned long long port_rsvd_th : 16;   // [87:72]
        unsigned long long port_drp_th_on : 16; // [103:88]
        unsigned long long port_drp_th_dif : 8; // [111:104]
        unsigned long long port_max_sh : 15;    // [126:112]
        unsigned long long port_sh_fc_dyn : 1;  // [127]

        unsigned long long port_fc_th_on0 : 16; // [15:0]
        unsigned long long port_fc_th_on1 : 16; // [31:16]
        unsigned long long port_fc_th_on2 : 16; // [47:32]
        unsigned long long port_fc_th_dif0 : 8; // [55:48]
        unsigned long long port_fc_th_dif1 : 8; // [63:56]
    } bs;
    unsigned long long val64[2];
} u_qu_pdm_nw_port_thd_cfg;


/*
    Network Cos cell occupied threshold table Fields Definition
    Total number :   128+2  .
"	Unicast :  	{1'b0, port/tp[3:0], cos[2:0]} .
"	Multicast(FIC): 	{5'h10, cos[0]}.
*/
typedef union {
    struct {
        unsigned long long cos_rsvd_th : 16;     // [15:0]
        unsigned long long cos_sh_fc_th_dif : 8; // [23:16]
        unsigned long long cos_sh_fc_th_on : 16; // [39:24]
        unsigned long long cos_drp_th_dif : 8;   // [47:40]
        unsigned long long cos_drp_th_on : 16;   // [63:48]
    } bs;
    unsigned long long val64;
} u_qu_pdm_nw_cos_thd_cfg;


/*
 */
typedef union {
    struct {
        unsigned long long cos_rsvd_th : 16;     // [15:0]
        unsigned long long cos_sh_fc_th_dif : 8; // [23:16]
        unsigned long long cos_sh_fc_th_on : 16; // [39:24]
        unsigned long long cos_sh_bp_th_dif : 8; // [47:40]
        unsigned long long cos_sh_bp_th_on : 16; // [63:48]
    } bs;
    unsigned long long val64;
} u_qu_pdm_host_que_thd_cfg;


/*
 */
typedef union {
    struct {
        unsigned long long sp_rsvd_th : 16;  // [15:0]
        unsigned long long sp_fc_th_dif : 8; // [23:16]
        unsigned long long sp_fc_th_on : 16; // [39:24]
        unsigned long long resv0 : 24;       // [63:40]
    } bs;
    unsigned long long val64;
} u_qu_pdm_host_pri_thd_cfg;


/*
 */
typedef union {
    struct {
        unsigned long long port_rsvd_th : 16;  // [15:0]
        unsigned long long port_fc_th_dif : 8; // [23:16]
        unsigned long long port_fc_th_on : 16; // [39:24]
        unsigned long long resv0 : 24;         // [63:40]
    } bs;
    unsigned long long val64;
} u_qu_pdm_host_port_thd_cfg;

/*
 */
typedef union {
    struct {
        unsigned long long sg_rsvd_th : 16;  // [15:0]
        unsigned long long sg_fc_th_dif : 8; // [23:16]
        unsigned long long sg_fc_th_on : 16; // [39:24]
        unsigned long long resv0 : 24;       // [63:40]
    } bs;
    unsigned long long val64;
} u_qu_pdm_host_srv_grp_thd_cfg;

typedef union {
    struct {
        unsigned int ep_bp_th_dif : 8; // [7:0]
        unsigned int ep_bp_th_on : 16; // [23:8]
        unsigned int rsv : 8;          // [31:24]
    } bs;

    unsigned int val32;
} u_qu_pdm_host_ep_grp_thd_cfg;

#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */

#endif /* HINIC3_CSR_ADDR_COMMON_H */
